package com.ungao.framework.scanner;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class PackageScanner {

    public List<String> scanPackage(String scanPackage) {
        List<String> classNames = new CopyOnWriteArrayList(new ArrayList());
        URL url = PackageScanner.class.getClassLoader().getResource(scanPackage.replaceAll("\\.", "/"));
        File classPath = new File(url.getFile());
        for (File file : classPath.listFiles()) {
            if (file.isDirectory()) {
                classNames.addAll(scanPackage(scanPackage + "." + file.getName()));
            } else {
                if (file.getName().endsWith("class")) {
                    String className = (scanPackage + "." + file.getName()).replace(".class", "");
                    classNames.add(className);
                }
            }
        }
        return classNames;
    }
}
